package com.googlecode.uipipedream.impl;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import com.googlecode.uipipedream.spec.ColourModel;

/**
 * <p>
 * Contains the user selected colours.
 * </p>
 * 
 * <p>
 * This file is part of UIPipeDream.
 * </p>
 * 
 * <p>
 * You can redistribute UIPipeDream and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 * </p>
 * 
 * <p>
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * </p>
 * 
 * <p>
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <a
 * href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>.
 * </p>
 * 
 * @author <a href="http://daemonsadvocate.blogspot.com/">Matthew B. Gray</a>
 * @author James Jones
 * @version 1.0 Final
 */
public class ColourSwatch extends Canvas {
	private static final long serialVersionUID = -8523194579277895075L;
	private ColourModel model;
	private Color color;

	@Override
	public Dimension preferredSize() {
		return new Dimension(20, 20);
	}

	@Override
	public Dimension minimumSize() {
		return new Dimension(5, 5);
	}

	public ColourSwatch(ColourModel model, Color color) {
		this.model = model;
		this.color = color;
		setBackground(Color.black);
	}

	public Color getColor() {
		return color;
	}

	public ColourModel getColourModel() {
		return this.model;
	}

	public void setColor(Color c) {
		color = c;
		repaint();
	}

	@Override
	public void paint(Graphics g) {
		g.setColor(color);
		g.fillRect(1, 1, getWidth() - 2, getHeight() - 2);
		g.setColor(Color.white);
		g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
	}

	@Override
	public void update(Graphics g) {
		super.update(g);
	}
}